package com.ych.sys.controller;

import com.ych.bean.Result;
import com.ych.sys.entity.PageResult;
import com.ych.sys.entity.dto.UserDto;
import com.ych.sys.entity.dto.UserPageDto;
import com.ych.sys.entity.po.UserPo;
import com.ych.sys.entity.req.UserPageReq;
import com.ych.sys.entity.req.UserReq;
import com.ych.sys.mapper.UserMapper;
import com.ych.sys.service.UserService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @BelongsProject: ape-frame
 * @BelongsPackage: com.ych.sys.controller
 * @Author: ych
 * @CreateTime: 2024-11-19  10:32
 * @Description: TODO
 * @Version: 1.0
 */

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;


    @PostMapping("/addUser")
    public Integer addUser(@RequestBody UserReq userReq) {
        UserDto userDto = new UserDto();
        BeanUtils.copyProperties(userReq, userDto);
        int count = userService.addUser(userDto);
        return count;
    }

    @DeleteMapping("/deleteUser/{id}")
    public Result deleteUser(@PathVariable Integer id) {
        return Result.ok(userService.deleteUser(id));
    }

    @GetMapping("/getUserPage")
    public Result getUserPage(@RequestBody UserPageReq userPageReq) {
        UserPageDto userPageDto = new UserPageDto();
        BeanUtils.copyProperties(userPageReq, userPageDto);
        return Result.ok(userService.getUserPage(userPageDto));
    }


    @GetMapping("/getUserList")
    public Result getUserList(Integer pageNum, Integer pageSize) {
        return Result.ok(userService.getUserList(pageNum, pageSize));
    }

}
